﻿using Md.Api.Entity.DapperModels.MdDB;
using Md.Api.Model.Manage.MdBanner.Request;
using Md.Dapper.Repositories.Md;

namespace Md.Api.Service.Manage.MdBanner;
/// <summary>
/// 通过编号更新轮播图服务
/// </summary>
public class UpdateMdBannerByIdService : ApiBase<RequestUpdateMdBannerByIdModel>
{
    /// <summary>
    /// 轮播图仓储
    /// </summary>
    public MdBannerRep mdBannerRep { get; set; }
    /// <summary>
    /// 执行
    /// </summary>
    protected override void ExecuteMethod()
    {
        var model = new MdBannerModel();

        model.BannerId = Parameter.BannerId;
        model.Title = Parameter.Title;
        model.Picture = Parameter.Picture;
        model.Url = Parameter.Url;
        model.Category = Parameter.Category;
        model.Sort = Parameter.Sort;
        model.Status = Parameter.Status;
        model.UpdateBy = userKey?.ToString();
        model.UpdateTime = DateTime.Now;

        var res = mdBannerRep.UpdateMdBannerById(model);

        if (res > 0)
        {
            Result.Data = mdBannerRep.GetMdBannerById(model.BannerId);
        }
        else
        {
            Result.Data = res;
        }
    }
}

